<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="box">
      <input type="text" v-model="message" id="msg" />
      <button onClick="cancel()">按钮</button>
    </div>
    <script src="../vue3.2.45.js"></script>

    <script>
      const options = {
        data() {
          return {
            message: "Vue 生命周期",
          };
        },
        beforeCreate() {
          console.log("--- 创建之前 ----");
          console.log(this.$el); // null
          console.log(this.$data); // {}
          console.log(this.message); //undefined
        },
        created() {
          console.log("--- 创建完成 ----");
          console.log(this.$el);
          console.log(this.$data);
          console.log(this.message);
        },
        beforeMount() {
          console.log("--- 挂载之前 ----");
          console.log(this.$el); // null
          console.log(this.$data);
          console.log(this.message);
        },
        mounted() {
          console.log("--- 挂载完毕 ----");
          console.log(this.$el);
          console.log(this.$data);
          console.log(this.message);
        },
        beforeUpdate() {
          console.log("--- 更新前 ----");
          console.log(document.querySelector("#msg").value);
          console.log(this.$el);
          console.log(this.$data);
          console.log(this.message);
        },
        updated() {
          console.log("--- 更新完毕 ----");
          console.log(document.querySelector("#msg").value);
          console.log(this.$el);
          console.log(this.$data);
          console.log(this.message);
        },
        beforeUnmount() {
          console.log("--- 销毁前 ----");
          console.log(this.$el);
          console.log(this.$data);
          console.log(this.message);
        },
        unmounted() {
          console.log("--- 销毁后 ----");
          console.log(this.$el);
          console.log(this.$data);
          console.log(this.message);
        },
        methods: {},
      };

      const app = Vue.createApp(options);
      app.mount("#box");

      function cancel() {
        app.unmount();
      }
    </script>
  </body>
</html>
